<!-- Manage Bills //-->

<div class="loader">
      <p><img src="images/loader.gif" alt="Loading..." /></p>
</div>

<%@ page import="com.checkfree.isolutions.customer.persist.*" %>
<%@ page import="com.checkfree.isolutions.statement.*" %>
<%@ page import="com.checkfree.isolutions.statement.persist.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.utils.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.controller.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.maxis.*" %>
<%@ page import="com.checkfree.isolutions.property.Properties" %>
<%@ page import="com.checkfree.isolutions.property.PropertiesConfig" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.text.*" %>
<%@ include file="../../@functions.jsp" %>
<%
final EbppxEcsUser ecsUser = (EbppxEcsUser) session.getAttribute(EbppxConstants.ECS_USER);
final String randomKey = (String) session.getAttribute(EbppxConstants.RANDOM_KEY);
final String statementId0 = (String) session.getAttribute("statementId0");
final String statementId1 = (String) session.getAttribute("statementId1");
final String statementsCount = (String) session.getAttribute("statementsCount");
List stmtDateList = (List) session.getAttribute("stmtDateList");
int stmtsCount = 0;
String amt = "";
String ref = "";
String msisdn = "";
String userid = "";
String stmtDate = "";
String accno = "";
String phoneNo = "";
String simNo = "";
String tempPhoneNo = "";
String tempSimNo = "";
String telSummUrl = "CusTelSumm";
String keySuffix = "_GSM_Key";
String telDetUrl = "CusTelDel";
String accessType = "";
String compareURL = "CompareBill_v1r00"+statementId0;
String [] DOWNLOAD_URL = {"DownloadBill_v1r00"+statementId0,"DownloadBill_v1r00"+statementId1};
String [] statementId = {statementId0,statementId1};
	
	List simList = new ArrayList();
	
	if(statementsCount != null){
		stmtsCount = Integer.parseInt(statementsCount);
	}
	
	if(ecsUser != null){
		userid = ecsUser.getUserId();
		msisdn = ecsUser.getMsisdn();
		accno = ecsUser.getSAccount();
		simNo = ecsUser.getSimNo();
		accessType = ecsUser.getAccessType();
		if(msisdn != null){
			phoneNo = msisdn;
		}
	}
	
	Map usageMap = new HashMap();
	List usageList = new ArrayList();
	List sectionTotal = new ArrayList();
	List sectionTitleList = new ArrayList();
	List compareStmtList = (ArrayList)request.getAttribute("compareStmtList");
	Statement statement0 = null;
	Statement statement1 = null;
	
	StatementSection cfiItemsWithoutRebateSection = null;
	StatementSection cfiSection2 = null;
	StatementSection cfiDiscountRebatesSection = null;
	StatementSection cfiServiceTaxSection = null;
	StatementSection cfiTotalLineChargesSection = null;
	StatementSection cfiMonthlyChargesSection = null;
	StatementSection cfiValueAddedServicesSection = null;
	StatementSection cfiUsageChargesSection = null;
	StatementSection cfiDomesticCallsSection = null;
	StatementSection cfiAdvantageSavingsSection = null;
	StatementSection cfiOtherChargesAndCreditSection = null;
	StatementSection cfiRegistrationChargesSection = null;
	StatementSection cfiAccessChargesSection = null;
	
	String totalLineChargesSection = "0";
	double totalAdvantageSavings = 0;
	double totalDiscountRebates = 0;
	double totalServiceTax = 0;
	double totalOtherChargesAndCredit = 0;
	double totalVAS = 0;
	double totalAccessChargesSection = 0;
	double totalRegistrationCharges = 0;
	double totalMonthlyCharges = 0;
	double totalUsageCharges = 0;
	DecimalFormat df = new DecimalFormat("0.00");
	List phoneIndex = new ArrayList();
	
	String strCompare = (String)request.getAttribute("comp");
	int comp = 0;
	if(strCompare != ""){
		comp = Integer.parseInt(strCompare);
	}

	if (compareStmtList.size() == 2){%>
<div class="manage-bills-container" style="display:none">
<div class="manage-bills col2">		
<%
	for(int sIndex = 0; sIndex < 2; sIndex++){
		totalLineChargesSection = "0";
		totalAdvantageSavings = 0;
		totalDiscountRebates = 0;
		totalServiceTax = 0;
		totalOtherChargesAndCredit = 0;
		totalVAS = 0;
		totalAccessChargesSection = 0;
		totalRegistrationCharges = 0;
		totalMonthlyCharges = 0;
		totalUsageCharges = 0;
		Statement cfiStatement = (Statement)compareStmtList.get(sIndex);
		List sectionTotalList = new ArrayList();
		List usage = new ArrayList();
	if(cfiStatement != null){
	    boolean found = false;
		StatementSection cfiRootSection = cfiStatement.getRootSection();
		stmtDate = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
		if(sIndex == 0){
			ref = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("ReferenceNumber"));
			amt = EbppxUtil.htmlEncode((cfiRootSection.getFieldText("TotalAmountDue")).replaceAll(" ",""));
		}
		
		StatementSection phoneNumberSection = null;
		StatementSection cfiSection = cfiRootSection.getSection("DetailsOfChargesSection");
        if (cfiSection != null){
            int sectionCount = (int) cfiSection.getSectionCount("PhoneNumberSection");
			int simIncrement = 0;
			
            for ( int index = 0; index < sectionCount; index++) {
                StatementSection cfiRSection0 = cfiSection.getRepeatSection("PhoneNumberSection", index);
                String str = cfiRSection0.getFieldText("PhoneNumber");


                if(str.indexOf(":")>=0){
					StringTokenizer st = new StringTokenizer(str,":");
					str = EbppxUtil.nullToEmpty(st.nextToken());
					str = str.replaceAll("\\(","");
					str = str.replaceAll("\\)","");
					if(!str.substring(0,2).equals("60")){
						str = "6"+str;
					}
				}

                if (phoneNo.equals(str)){
					simIncrement++;
                    found = true;
					String tempSimNo_1 = cfiRSection0.getFieldText("SimNumber");

					if(tempSimNo_1 != null && tempSimNo_1.indexOf(":")>=0){
						StringTokenizer stTempSim = new StringTokenizer(tempSimNo_1,":");
						tempSimNo_1 = EbppxUtil.nullToEmpty(stTempSim.nextToken());
						tempSimNo_1 = tempSimNo_1.replaceAll("\\(", "");
						tempSimNo_1 = tempSimNo_1.replaceAll("\\)","");
						if(sIndex == 0){
							simList.add(tempSimNo_1);
						}

						if(simNo.equals("") && simIncrement == 1){
							phoneNumberSection = cfiRSection0;
							tempSimNo = tempSimNo_1;
							phoneIndex.add(new Integer(index));
						}
						else if(simNo.equals(tempSimNo_1)){
							phoneNumberSection = cfiRSection0;
							tempSimNo = tempSimNo_1;
							phoneIndex.add(new Integer(index));
						}
					}else{
						cfiSection = cfiRSection0;
						phoneNumberSection = cfiRSection0;
						phoneIndex.add(new Integer(index));
						break;
					}
                }
            }
            if (!found){
                cfiSection = null;
            }
        }
/*
Section 0:			ItemsWithoutRebateSection
Section 0_0:		PaymentsSection
Section 0_1:		AdjustmentsSection
Section 0_2:		AdjustmentsServiceTaxSection


Section 1:			ItemsWithRebateSection
Section 1_0:		RegistrationChargesSection
Section 1_1:		AccessChargesSection
Section 1_2:		ValueAddedServicesSection
Section 1_3:		UsageChargesSection
Section 1_4:		DiscountAndRebatesSection
Section 1_5:		OtherChargesAndCreditSection
Section 1_6:		ServiceTaxSection
Section 1_7:		MonthlyChargesSection
Section 1_8:		AdvantageSavingsSection
Section 1_total:	TotalLineChargesSection
*/
	if(found){	

		if(cfiSection != null) {
			cfiItemsWithoutRebateSection = phoneNumberSection.getSection("ItemWithRebateSection");
			cfiSection2 = phoneNumberSection.getSection("RoamingCallsSection");
			if(cfiItemsWithoutRebateSection != null) {
				
				cfiRegistrationChargesSection 	= cfiItemsWithoutRebateSection.getSection("RegistrationChargesSection");
	            cfiAccessChargesSection 		= cfiItemsWithoutRebateSection.getSection("AccessChargesSection");
				cfiValueAddedServicesSection	= cfiItemsWithoutRebateSection.getSection("ValueAddedServicesSection");
				cfiUsageChargesSection 			= cfiItemsWithoutRebateSection.getSection("UsageChargesSection");
				cfiDiscountRebatesSection 		= cfiItemsWithoutRebateSection.getSection("DiscountAndRebatesSection");
				cfiOtherChargesAndCreditSection	= cfiItemsWithoutRebateSection.getSection("OtherChargesAndCreditSection");
				cfiServiceTaxSection 			= cfiItemsWithoutRebateSection.getSection("ServiceTaxSection");
				cfiMonthlyChargesSection 		= cfiItemsWithoutRebateSection.getSection("MonthlyChargesSection");
				cfiAdvantageSavingsSection 		= cfiItemsWithoutRebateSection.getSection("AdvantageSavingsSection");
				cfiTotalLineChargesSection 		= cfiItemsWithoutRebateSection.getSection("TotalLineChargesSection");		
			}
		}

			if(cfiTotalLineChargesSection != null){
				totalLineChargesSection = cfiTotalLineChargesSection.getFieldText("Total");
			}
			sectionTotalList.add(totalLineChargesSection);
			
			if(cfiMonthlyChargesSection != null){
				totalMonthlyCharges = getSectionTotal(cfiMonthlyChargesSection);
				if(!sectionTitleList.contains("cfiMonthlyChargesSection"))
					sectionTitleList.add("cfiMonthlyChargesSection");
			}
			sectionTotalList.add(new Double(totalMonthlyCharges));
			
			if(cfiRegistrationChargesSection != null){
				totalRegistrationCharges = getSectionTotal(cfiRegistrationChargesSection);
				if(!sectionTitleList.contains("cfiRegistrationChargesSection"))
					sectionTitleList.add("cfiRegistrationChargesSection");
			}
			sectionTotalList.add(new Double(totalRegistrationCharges));
			
			if(cfiAccessChargesSection != null){
				totalAccessChargesSection = getSectionTotal(cfiAccessChargesSection);
				if(!sectionTitleList.contains("cfiAccessChargesSection"))
					sectionTitleList.add("cfiAccessChargesSection");				
			}
			sectionTotalList.add(new Double(totalAccessChargesSection));
			
			if(cfiValueAddedServicesSection != null){
				totalVAS = getSectionTotal(cfiValueAddedServicesSection);
				if(!sectionTitleList.contains("cfiValueAddedServicesSection"))
					sectionTitleList.add("cfiValueAddedServicesSection");
			}
			sectionTotalList.add(new Double(totalVAS));
			
			if(cfiUsageChargesSection != null){
				int sectionCount1_3 = (int) cfiUsageChargesSection.getSectionCount("RepeatSection");
                for (int index1_3 = 0; index1_3 < sectionCount1_3; index1_3++) {
                    StatementSection cfiRSection1_3 = cfiUsageChargesSection.getRepeatSection("RepeatSection", index1_3);
					double total =0;
                    String item = cfiRSection1_3.getFieldText("Item");
					if(item.equals("Usage Charges")){
						totalUsageCharges = getSectionTotal(cfiUsageChargesSection);
						usage.add(item+"_"+totalUsageCharges);
					}else{
						int subRepeatSectionCount = (int) cfiRSection1_3.getSectionCount("SubRepeatSection");
						if(subRepeatSectionCount == 0){
							double amount = getFieldAmount(cfiRSection1_3,"Amount");
							total += amount;
						}else{
							for (int index1_1 = 0; index1_1 < subRepeatSectionCount; index1_1++) {
								StatementSection subRepeatSection = cfiRSection1_3.getRepeatSection("SubRepeatSection", index1_1);
								if(subRepeatSection != null){
									String repeatItem1 = subRepeatSection.getFieldText("Item");
									double amount = getFieldAmount(subRepeatSection,"Amount");
									total += amount;
								}
							}
						}	
						totalUsageCharges += total;
						if(sIndex == 0){
							usageMap.put(item, Double.toString(total));
						}else if(sIndex ==1 ){
							if(usageMap.containsKey(item)){
								String charges = (String)usageMap.get(item);
								usageMap.put(item, charges+"_"+total);
							}else{
								usageMap.put(item, "0_"+total);
							}
						}
						usage.add(item+"_"+total);
					}
					if(!sectionTitleList.contains(item))
						sectionTitleList.add(item);
				}
                usageList.add(usage);
			}
			sectionTotalList.add(new Double(totalUsageCharges));

			if(cfiAdvantageSavingsSection != null){
				totalAdvantageSavings = getSectionTotal(cfiAdvantageSavingsSection);
				if(!sectionTitleList.contains("cfiAdvantageSavingsSection"))
					sectionTitleList.add("cfiAdvantageSavingsSection");
			}
			sectionTotalList.add(new Double(totalAdvantageSavings));
			
			if(cfiDiscountRebatesSection != null){
				totalDiscountRebates = getSectionTotal(cfiDiscountRebatesSection);
				if(!sectionTitleList.contains("cfiDiscountRebatesSection"))
					sectionTitleList.add("cfiDiscountRebatesSection");
			}
			sectionTotalList.add(new Double(totalDiscountRebates));
			
			if(cfiOtherChargesAndCreditSection != null){
				totalOtherChargesAndCredit = getSectionTotal(cfiOtherChargesAndCreditSection);
				if(!sectionTitleList.contains("cfiOtherChargesAndCreditSection"))
					sectionTitleList.add("cfiOtherChargesAndCreditSection");
			}
			sectionTotalList.add(new Double(totalOtherChargesAndCredit));
			
			if(cfiServiceTaxSection != null){
				totalServiceTax = getSectionTotal(cfiServiceTaxSection);
				if(!sectionTitleList.contains("cfiServiceTaxSection"))
					sectionTitleList.add("cfiServiceTaxSection");
			}
			sectionTotalList.add(new Double(totalServiceTax));
			
			//add totalamountdue
			sectionTotalList.add((cfiRootSection.getFieldText("TotalAmountDue")).substring(2));
			
			//add current list into list
			sectionTotal.add(sectionTotalList);
			
		} else{
			//statement not found in previous bill, create dummy data
			sectionTotalList.add("MSISDN not found");
			int dum1 = 0;
			while(dum1 < 10){
				sectionTotalList.add(new Double(0));
				dum1++;
			}
			sectionTotal.add(sectionTotalList);
		}
	}
}

//start drawing html
int cfiEndIndex = sectionTitleList.size();
List sectionTotal0 = (List)sectionTotal.get(0);
List sectionTotal1 = (List)sectionTotal.get(1);

for(int cIndex =0; cIndex < 2; cIndex++){
	//List currentUsage = (List)usageList.get(cIndex);
	List currentSectionTotal = (List)sectionTotal.get(cIndex);
	int count = 0;
	String stmtIndex = "";
	String cStmtdate = "";
	if(cIndex == 0){
		stmtIndex = EncryptionHelper.encodeURL(EncryptionHelper.encrypt(Integer.toString(0), randomKey));
	}else{
		stmtIndex = EncryptionHelper.encodeURL(EncryptionHelper.encrypt(Integer.toString(comp), randomKey));
	}
%>
<script type="text/javascript">
function manageBill<%=cIndex%>(){
document.write("<div class='manage-bill-actions'>");
<%if(accessType.equals("P")){%>
document.write("<a href=<%=DOWNLOAD_URL[cIndex]%> class='download-bill'>Download Bill</a>");
<%}
if(cIndex == 0){%>
document.write("<a href='CusConfirmPayment.jsp?username=<%=userid%>&accid=<%=accno%>&statid=<%=ref%>&amt=<%=amt%>&lflag=E' class='btn paynow'>Pay Bill Now<i class='icon-chevron-right'></i></a>");
<%}%>
document.write("</div>");
}
</script>
	<div class="manage-bill month<%=cIndex%>">
		<div class="detailed-bill">
			<div class="charges">
				<ul>
					<li class="details">
<%						if(cIndex == 0){
							cStmtdate = (String)stmtDateList.get(0);
						}else{
							cStmtdate = (String)stmtDateList.get(comp);
						}
%>						<h4>Bill date: <%=cStmtdate%></h4>
						<!-- <h4>Total Amount Due</h4> -->
						<!-- <h1><sup>RM</sup><%=currentSectionTotal.get(10)%></h1> -->
<%						if(cIndex == 0 && simList.size() > 0){ %>
						<form>
						<div class="multisim">
						<h5>SIM Card Number :</h5>
							<span class="select-custom">
								<select name="multisim" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
									<% if(simList.size() > 0) {
										for(int i = 0; i < simList.size(); i++){
											String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
											String urlToDirect = host+"/cust_sso/"+compareURL+"&simno="+simList.get(i)+"&comp=1";
									%>
										<option value="<%=urlToDirect%>" <%if(tempSimNo.equals(simList.get(i))){%>selected<%}%>><%=simList.get(i)%></option>
									<%	}
									}%>
								</select>
							</span>
						</div>
						</form>
<%}						
						if(cIndex == 0){
%>						<form id="cusPayment" name="cusPayment" method="post" action="CusConfirmPayment.jsp">
							<input id="accid" name="accid" type="hidden" value="<%=accno%>">
							<input id="statid" name="statid" type="hidden" value="<%=ref%>">
							<input id="amt" name="amt" type="hidden" value="<%=amt%>">
							<input id="lflag" name="lflag" type="hidden" value="E">
						</form>
						<a href="#" class="btn paynow">Pay Bill Now<i class="icon-chevron-right"></i></a>
						<a href="CusBillList_v1r00<%if(simNo != ""){%>?simno=<%=simNo%><%}%>" class="btn blue">Current Bill</a>
<%						}else if(cIndex == 1){%>
						<form>
						<div class="select">
							<span class="select-custom">
								<select name="month" onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
									<% if(stmtDateList.size() > 0) {
										for(int i = 1; i < stmtDateList.size(); i++){
											String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
											String urlToDirect = host+"/cust_sso/"+compareURL+"&simno="+simNo+"&comp="+i;
									%>
										<option value="<%=urlToDirect%>" <%if(comp == i){%>selected<%}%>><%=stmtDateList.get(i)%></option>
									<%}%>
									<%}%>
								</select>
							</span>
						</div>
						</form>
<%						}
%>
						<br />
					<%	if(accessType.equals("P")){
					%>		<a href=<%=DOWNLOAD_URL[cIndex]%> class="download-bill">Download Bill</a>
					<%	}
						if(currentSectionTotal.get(0).toString().equalsIgnoreCase("MSISDN not found")){%>
							<br />
							<div class='number-missing'>
								<p>Service number not exist in selected bill.</p>
								<p>No details to display.</p>
							</div>
						</li>
<%						}else{					
					%>
					
					<h6 <%if(cIndex == 0 && simList.size() > 0)out.print("class='total-line-charges-sim'");%>>Total Line Charges <br /><span class="total-line-charges"><sup>RM</sup><%=currentSectionTotal.get(0)%></span></h6>
					</li>
					
					<!-- Display monthly charges//-->
					<% 	double monthlyCharges0 = ((Double)sectionTotal0.get(1)).doubleValue();
						double monthlyCharges1 = ((Double)sectionTotal1.get(1)).doubleValue();
					if( monthlyCharges0 != 0 || monthlyCharges1 != 0){
						double cMonthlyCharges = ((Double)currentSectionTotal.get(1)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Monthly Charges", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("MonthlyChargesSection", randomKey));
					%>
					<li class="green monthly-charges <%count++;if((count %2) == 0){%> alt <%}%>"><label>Monthly Charges</label><sup>RM</sup><%=formatAmount(cMonthlyCharges)%><br />
						<%if(cMonthlyCharges != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display totalRegistrationCharges //-->
					<% 	double registrationCharges0 = ((Double)sectionTotal0.get(2)).doubleValue();
						double registrationCharges1 = ((Double)sectionTotal1.get(2)).doubleValue();
					if( registrationCharges0 != 0 || registrationCharges1 != 0){
						double cRegistrationCharges = ((Double)currentSectionTotal.get(2)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Registration Charges", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("RegistrationChargesSection", randomKey));%>
					<li class="green monthly-charges <%count++;if((count %2) == 0){%> alt <%}%>"><label>Registration Charges</label><sup>RM</sup><%=formatAmount(cRegistrationCharges)%><br />
						<%if(cRegistrationCharges != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display totalAccessChargesSection //-->
					<% 	double accessCharges0 = ((Double)sectionTotal0.get(3)).doubleValue();
						double accessCharges1 = ((Double)sectionTotal1.get(3)).doubleValue();
					if( accessCharges0 != 0 || accessCharges1 != 0){
						double cAccessCharges = ((Double)currentSectionTotal.get(3)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Access Charges", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("AccessChargesSection", randomKey));%>
					<li class="green monthly-charges <%count++;if((count %2) == 0){%> alt <%}%>"><label>Access Charges</label><sup>RM</sup><%=formatAmount(cAccessCharges)%><br />
						<%if(cAccessCharges != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display VAS-->
					<% 	double vasCharges0 = ((Double)sectionTotal0.get(4)).doubleValue();
						double vasCharges1 = ((Double)sectionTotal1.get(4)).doubleValue();
					if( vasCharges0 != 0 || vasCharges1 != 0){
						double cVasCharges = ((Double)currentSectionTotal.get(4)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Value Added Services", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("ValueAddedServicesSection", randomKey));%>
					<li class="lightgreen <%count++;if((count %2) == 0){%> alt <%}%>"><label>Value Added Services</label><sup>RM</sup><%=formatAmount(cVasCharges)%><br />
						<%if(cVasCharges != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display usage charges-->
					<% 	double usageCharges0 = ((Double)sectionTotal0.get(5)).doubleValue();
						double usageCharges1 = ((Double)sectionTotal1.get(5)).doubleValue();
					if( usageCharges0 != 0 || usageCharges1 != 0){
						// Get a set of the entries 
						Set set = usageMap.entrySet(); 
						// Get an iterator 
						Iterator i1 = set.iterator(); 
						// Display elements 
						while(i1.hasNext()) { 
						Map.Entry me = (Map.Entry)i1.next(); 
						String item_value = me.getValue().toString();
						if(item_value.indexOf("_") < 0){
							item_value = item_value+"_0";
						}
						String[] item = item_value.split("_");
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt((String)me.getKey(), randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt(((String)me.getKey()).replaceAll(" ", "")+"Section", randomKey));
						%>
								<li class="seagreen domestic-charges <% count++;if((count %2) == 0){%> alt <%}%>"><label><%=me.getKey()%></label><sup>RM</sup><%=formatAmount(Double.parseDouble(item[cIndex]))%><br />
								<%if(!(me.getKey().equals("Usage Charges")) && !item[cIndex].equals("0")){%>
									<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%		}else{%>
									<p>&nbsp;</p>
									<%}%>
								</li>
						<%}
					}%>
					
					<!-- Display advantage savings-->
					<%	double advantageSavings0 = ((Double)sectionTotal0.get(6)).doubleValue();
						double advantageSavings1 = ((Double)sectionTotal1.get(6)).doubleValue();
					if( advantageSavings0 != 0 || advantageSavings1 != 0){
						double cAdvantageSavings = ((Double)currentSectionTotal.get(6)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Advantage Savings", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("AdvantageSavingsSection", randomKey));%>
					<li class="babyblue roaming-charges <% count++;if((count %2) == 0){%> alt <%}%>"><label>Advantage Savings</label><sup>RM</sup><%=formatAmount(cAdvantageSavings)%><br />
						<%if(cAdvantageSavings != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display discount and rebates -->
					<% 	double discountAndRebates0 = ((Double)sectionTotal0.get(7)).doubleValue();
						double discountAndRebates1 = ((Double)sectionTotal1.get(7)).doubleValue();
					if( discountAndRebates0 != 0 || discountAndRebates1 != 0){
						double cDiscountAndRebates = ((Double)currentSectionTotal.get(7)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Discounts & Rebates", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("DiscountAndRebatesSection", randomKey));%>
					<li class="dullerblue discounts-rebates <% count++;if((count %2) == 0){%> alt <%}%>"><label>Discounts &amp; Rebates</label><sup>RM</sup><%=formatAmount(cDiscountAndRebates)%><br />
						<%if(cDiscountAndRebates != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display other charges -->
					<% 	double otherCharges0 = ((Double)sectionTotal0.get(8)).doubleValue();
						double otherCharges1 = ((Double)sectionTotal1.get(8)).doubleValue();
					if( otherCharges0 != 0 || otherCharges1 != 0){
						double cOtherCharges = ((Double)currentSectionTotal.get(8)).doubleValue();
						String param = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("Other Charges & Credit", randomKey));
						String param1 = EncryptionHelper.encodeURL(EncryptionHelper.encrypt("OtherChargesAndCreditSection", randomKey));%>
					<li class="dullerblue discounts-rebates <% count++;if((count %2) == 0){%> alt <%}%>"><label>Other Charges &amp; Credit</label><sup>RM</sup><%=formatAmount(cOtherCharges)%><br />
						<%if(cOtherCharges != 0){%>
							<p><a href="ChargesDetails_v1r00?phoneIndex=<%=phoneIndex.get(cIndex)%>&type=<%=param%>&typeIndex=<%=param1%>&stmtIndex=<%=stmtIndex%>" class="detailed-charges">Details of charges</a></p>
						<%}else{%>
							<p>&nbsp;</p>
						<%}%>
					</li>
					<%}%>
					
					<!-- Display service tax-->
					<% 	double tax0 = ((Double)sectionTotal0.get(9)).doubleValue();
						double tax1 = ((Double)sectionTotal1.get(9)).doubleValue();
					if(tax0 != 0 || tax1 != 0){%>
					<li class="blue service-tax <% count++;if((count %2) == 0){%> alt <%}%>"><label>Service Tax</label><sup>RM</sup><%=formatAmount(((Double)currentSectionTotal.get(9)).doubleValue())%><br />
						<p>Monthly Charges and Value Added Services</p>
					</li>
<%					}
				}
%>
				</ul>
			</div>
		</div>
</div>		
<%}//End draw html for loop	
	}else{//if statementlist != 2 %>
		<div class="manage-bills col0">
			<p>Error occur when retrieve bills.</p>
			<!-- <p>The next payment amount due is on <strong>24th February 2013</strong>.</p> -->
		</div>
<%}%>
</div>
</div>
<!-- #END Current Month (Principle Number) //-->	

<script type="text/javascript">
	$(document).ready(function() {
	
		$(".detailed-charges,._paynow,.download-bill,.pop").fancybox({
	    	type		: 'ajax',
			width		: 600,
			height		: 600,
			fitToView	: true,
			autoSize	: true,
			closeClick	: false,
			openEffect	: 'fade',
			closeEffect	: 'fade',
			padding		: 0
		});

	    $(".paynow").click(function(event){
	    	event.preventDefault();
	    	 $("#cusPayment").submit();
	    });

	    $("#cusPayment").submit(function() {
	        $.fancybox.showLoading(); // start fancybox loading animation
	        $.ajax({
	            data: $(this).serialize(), // get the form data
	            type: $(this).attr('method'), // GET or POST
	            url: $(this).attr('action'), // the file to call
	            success: function(response) { // on success..
	                $.fancybox({ 'content' : response }); // target response to fancybox
	            },
	            complete: function() { // on complete...
	                $.fancybox.hideLoading(); //stop fancybox loading animation
	            }
	        });
	        return false; // stop default submit event propagation
	    });

		$('.col2').show();
		var width = $(window).width();
		if (width <= 492) {
			var containerWidth = $('.manage-bills-container .manage-bill').width();
			$('.manage-bills-container').find('.manage-bills').animate({
				marginLeft: '-='+containerWidth+'px'
			}, 500);
		}
		
		$(".loader").fadeOut(2000, function() {
			$(".manage-bills-container").fadeIn(1000,function() {
				iframeResizePipe();
			});  						
		});
		
	});
</script>
